/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jeff.springmvcstudy.mbean;

import java.util.ArrayDeque;
import java.util.Date;
import java.util.Queue;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

/**
 *
 * @author winnie
 */
@Service
@Lazy(false)
public class QueueSampler implements IQueueSampler {
    private Queue<String> queue = new ArrayDeque<String>();

    @Override
    public QueueSample getQueueSample() {
        synchronized(queue) {
            return new QueueSample(new Date(), queue.size(), queue.peek());
        }
    }

    @Override
    public void addToQueue(String content) {
        synchronized(queue) {
            queue.offer(content);
        }
    }

    @Override
    public void clearQueue() {
        synchronized(queue) {
            queue.clear();
        }
    }
    
}
